       IDENTIFICATION DIVISION.
       PROGRAM-ID. TP.
       AUTHOR. Grupo 5. 2do cuatrimestre 2011.

       ENVIRONMENT DIVISION.
         INPUT-OUTPUT SECTION.
           FILE-CONTROL.
             SELECT ASI1-ARCH ASSIGN TO "ASIGNACIONES1.DAT"
             ORGANIZATION IS LINE SEQUENTIAL.

             SELECT ASI2-ARCH ASSIGN TO "ASIGNACIONES2.DAT"
             ORGANIZATION IS LINE SEQUENTIAL.

             SELECT ASI3-ARCH ASSIGN TO "ASIGNACIONES3.DAT"
             ORGANIZATION IS LINE SEQUENTIAL.

             SELECT SOL-ARCH ASSIGN TO "SOLICITUDES.DAT"
             ORGANIZATION IS LINE SEQUENTIAL.

             SELECT CLI-ARCH ASSIGN TO "CLIENTES.DAT"
             ORGANIZATION IS LINE SEQUENTIAL.

             SELECT VAL-ARCH ASSIGN TO "VALORES.DAT"
             ORGANIZATION IS LINE SEQUENTIAL.

             SELECT SASI-ARCH ASSIGN TO "SINASIGNACION.DAT"
             ORGANIZATION IS LINE SEQUENTIAL.

             SELECT ERR-ARCH ASSIGN TO "ERRORES.DAT"
             ORGANIZATION IS LINE SEQUENTIAL.

       DATA DIVISION.
         FILE SECTION.
           FD ASI1-ARCH.
           01 ASI1-REG.
             88 ASI1-EOF          VALUE HIGH-VALUES.
             02 ASI1-CLAVE.
               03 ASI1-COD-CLI    PIC X(06).
               03 ASI1-FECHA      PIC 9(08).
               03 ASI1-PERFIL     PIC X(04).
               03 ASI1-SENIORITY  PIC X(03).
             02 ASI1-COD-EMPLE    PIC 9(05).
             02 ASI1-CANT-HORAS   PIC 9(03).

           FD ASI2-ARCH.
           01 ASI2-REG.
             88 ASI2-EOF          VALUE HIGH-VALUES.
             02 ASI2-CLAVE.
               03 ASI2-COD-CLI    PIC X(06).
               03 ASI2-FECHA      PIC 9(08).
               03 ASI2-PERFIL     PIC X(04).
               03 ASI2-SENIORITY  PIC X(03).
             02 ASI2-COD-EMPLE    PIC 9(05).
             02 ASI2-CANT-HORAS   PIC 9(03).

           FD ASI3-ARCH.
           01 ASI3-REG.
             88 ASI3-EOF          VALUE HIGH-VALUES.
             02 ASI3-CLAVE.
               03 ASI3-COD-CLI    PIC X(06).
               03 ASI3-FECHA      PIC 9(08).
               03 ASI3-PERFIL     PIC X(04).
               03 ASI3-SENIORITY  PIC X(03).
             02 ASI3-COD-EMPLE    PIC 9(05).
             02 ASI3-CANT-HORAS   PIC 9(03).

           FD SOL-ARCH.
           01 SOL-REG.
             88 SOL-EOF           VALUE HIGH-VALUES.
             02 SOL-CLAVE.
               03 SOL-COD-CLI     PIC X(06).
               03 SOL-FECHA       PIC 9(08).
               03 SOL-PERFIL      PIC X(04).
               03 SOL-SENIORITY   PIC X(03).
             02 SOL-CANT-HORAS    PIC 9(03).

           FD CLI-ARCH.
           01 CLI-REG.
             88 CLI-EOF           VALUE HIGH-VALUES.
             02 CLI-COD-CLI       PIC X(06).
             02 CLI-CUIT          PIC 9(11).
             02 CLI-DESC          PIC X(30).
             02 CLI-CATEGORIA     PIC 9(02).

           FD VAL-ARCH.
           01 VAL-REG.
             88 VAL-EOF           VALUE HIGH-VALUES.
             02 VAL-PERFIL        PIC X(04).
             02 VAL-SENIORITY     PIC X(03).
             02 VAL-ELEMENTO      OCCURS 50 TIMES.
               03 VAL-CAT         PIC 9(02).
               03 VAL-VALOR       PIC 9(03)V99.

           FD SASI-ARCH.
           01 SASI-REG.
             88 SASI-EOF          VALUE HIGH-VALUES.
             02 SASI-COD-CLI      PIC X(06).
             02 SASI-FECHA        PIC 9(08).
             02 SASI-PERFIL       PIC X(04).
             02 SASI-SENIORITY    PIC X(03).
             02 SASI-CANT-HORAS   PIC 9(03).

           FD ERR-ARCH.
           01 ERR-REG.
             88 ERR-EOF           VALUE HIGH-VALUES.
             02 ERR-COD-CLI       PIC X(06).
             02 ERR-FECHA         PIC 9(08).
             02 ERR-PERFIL        PIC X(04).
             02 ERR-SENIORITY     PIC X(03).
             02 ERR-COD-EMPLE     PIC 9(05).
             02 ERR-CANT-HORAS    PIC 9(03).

         WORKING-STORAGE SECTION.
           01 TotalHorasGeneral      PIC 9(06)    VALUE ZEROS.
           01 TotalValorGeneral      PIC 9(06)V99 VALUE ZEROS.
           01 TotalHorasCliente      PIC 9(06)    VALUE ZEROS.
           01 TotalValorCliente      PIC 9(06)V99 VALUE ZEROS.
           01 TotalHorasFecha        PIC 9(06)    VALUE ZEROS.
           01 TotalValorFecha        PIC 9(06)V99 VALUE ZEROS.
           01 TotalHorasPerfilSenior PIC 9(06)    VALUE ZEROS.
           01 TotalValorPerfilSenior PIC 9(06)V99 VALUE ZEROS.
           01 HorasAsignacion        PIC 9(06)    VALUE ZEROS.

           01 SOL-COD-CLI-ANT        PIC X(06).
           01 SOL-FECHA-ANT.
             02 SOL-ANIO-ANT         PIC X(04).
             02 SOL-MES-ANT          PIC X(02).
             02 SOL-DIA-ANT          PIC X(02).
           01 SOL-PERFIL-ANT         PIC X(04).
           01 SOL-SENIORITY-ANT      PIC X(03).
           01 SOL-CANT-HORAS-ANT     PIC 9(03).

           01 HayAsignaciones        PIC X(02).

           01 FechaActual.
             02 AnioActual           PIC X(04).
             02 MesActual            PIC X(02).
             02 DiaActual            PIC X(02).

           01 Pagina                 PIC 9(02) VALUE ZEROS.

           01 I                      PIC 9(03).
	   01 J                      PIC 9(03).
           01 TablaValores.
             02 ItemValores          OCCURS 100 TIMES.
               03 TVL-PERFIL         PIC X(04).
               03 TVL-SENIORITY      PIC X(03).
               03 TVL-CATEGORIAS     OCCURS 50 TIMES.
                 04 TVL-VALOR        PIC 9(03)V99.
           
           01 ValorHora              PIC 9(03)V99.
           01 ValorAsignacion        PIC 9(06)V99  VALUE ZEROS.

	   01 Tabla-Perfiles.
	     02 ValoresTabPerfiles.
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "".
	       03 FILLER       PIC X(04) VALUE "TOT".
	     02 FILLERh REDEFINES ValoresTabPerfiles.
	       03 TabPerfiles OCCURS 21 TIMES PIC X(04).

	   01 Tabla-Senioritys.
	     02 ValoresTabSeniority.
	       03 FILLER       PIC X(03) VALUE "".
	       03 FILLER       PIC X(03) VALUE "".
	       03 FILLER       PIC X(03) VALUE "".
	       03 FILLER       PIC X(03) VALUE "".
	       03 FILLER       PIC X(03) VALUE "".
	       03 FILLER       PIC X(03) VALUE "".
	       03 FILLER       PIC X(03) VALUE "TOT".
	     02 FILLERh REDEFINES ValoresTabSeniority.	      
	       03 TabSenioritys OCCURS 7 TIMES PIC X(03).

	   01 Tab-Horas-No-Asig.
	     02 SENIORITY OCCURS 7 TIMES.
 	       03 PERFIL OCCURS 21 TIMES PIC 9(03).

	   01 PosPerfil PIC 9(03).
	   01 PosSenior PIC 9(03).
	   01 Encontro	PIC X(02).
	   01 Existe	PIC X(02).	
 	   01 seniorFilaLibre PIC 9(03) VALUE 1.
 	   01 perfilFilaLibre PIC 9(03) VALUE 1.


       PROCEDURE DIVISION.
         PERFORM Inicio

         PERFORM CargarTablaValores

         PERFORM ListarTitulo

         MOVE 0 TO TotalHorasGeneral
         MOVE 0 TO TotalValorGeneral

         PERFORM LeerSolicitudes

         PERFORM LeerAsignaciones

         PERFORM UNTIL SOL-EOF
           MOVE 0 TO TotalHorasCliente
           MOVE 0 TO TotalValorCliente
           
           MOVE SOL-COD-CLI TO SOL-COD-CLI-ANT

           PERFORM ListarCliente
  
           PERFORM UNTIL SOL-EOF
                         OR SOL-COD-CLI <> SOL-COD-CLI-ANT
             MOVE 0 TO TotalHorasFecha
             MOVE 0 TO TotalValorFecha
             
             MOVE SOL-FECHA TO SOL-FECHA-ANT

             PERFORM ListarFecha
             
             PERFORM ListarTitulos
            
             PERFORM UNTIL SOL-EOF
                           OR SOL-COD-CLI <> SOL-COD-CLI-ANT
                           OR SOL-FECHA <> SOL-FECHA-ANT
               
               MOVE 0 TO TotalHorasPerfilSenior
               MOVE 0 TO TotalValorPerfilSenior
               MOVE 0 TO HorasAsignacion
               
               MOVE SOL-PERFIL TO SOL-PERFIL-ANT
               MOVE SOL-SENIORITY TO SOL-SENIORITY-ANT
               MOVE SOL-CANT-HORAS TO SOL-CANT-HORAS-ANT

               PERFORM UNTIL SOL-EOF
                             OR SOL-COD-CLI <> SOL-COD-CLI-ANT
                             OR SOL-FECHA <> SOL-FECHA-ANT
                             OR SOL-PERFIL <> SOL-PERFIL-ANT
                             OR SOL-SENIORITY <> SOL-SENIORITY-ANT

		 PERFORM GrabarSeniority
		 PERFORM GrabarPerfil

                 MOVE 'NO' TO HayAsignaciones
                 
                 PERFORM ProcesarAsignaciones1

                 PERFORM ProcesarAsignaciones3

                 PERFORM ProcesarAsignaciones2

                 IF HayAsignaciones = 'NO'
                   PERFORM GrabarErrorSolicitud
                 END-IF

                 PERFORM LeerSolicitudes

               END-PERFORM
             
               IF HorasAsignacion = SOL-CANT-HORAS-ANT
                 PERFORM ListarPerfilSenior
                 
                 ADD HorasAsignacion TO TotalHorasPerfilSenior
                 ADD ValorAsignacion TO TotalValorPerfilSenior
               END-IF

               ADD TotalHorasPerfilSenior TO TotalHorasFecha
               ADD TotalValorPerfilSenior TO TotalValorFecha

             END-PERFORM

             PERFORM ListarTotalFecha

             ADD TotalHorasFecha TO TotalHorasCliente
             ADD TotalValorFecha TO TotalValorCliente

           END-PERFORM

           PERFORM ListarTotalCliente

           ADD TotalHorasCliente TO TotalHorasGeneral
           ADD TotalValorCliente TO TotalValorGeneral

         END-PERFORM

         PERFORM ListarTotalGeneral
         
         PERFORM DescartarAsignaciones
         
	 DISPLAY "--------------------------------------------"
 	 DISPLAY "------------------ TP1 B -------------------"
	 DISPLAY "--------------------------------------------"

	 PERFORM ListarTituloB

	 PERFORM ListarTitulosB

	 PERFORM ListarSolicitudesSinAsignacion

         PERFORM Fin 
          
         STOP RUN
         .

       Inicio.
         OPEN INPUT ASI1-ARCH
         OPEN INPUT ASI2-ARCH
         OPEN INPUT ASI3-ARCH
         OPEN INPUT SOL-ARCH
         OPEN OUTPUT SASI-ARCH
         OPEN OUTPUT ERR-ARCH
         .

       Fin.
         CLOSE ASI1-ARCH
         CLOSE ASI2-ARCH
         CLOSE ASI3-ARCH
         CLOSE SOL-ARCH
         CLOSE SASI-ARCH
         CLOSE ERR-ARCH
         .

       ListarTitulo.
         MOVE FUNCTION CURRENT-DATE() TO FechaActual
         ADD 1 TO Pagina

         DISPLAY "Fecha "
                 DiaActual "/" MesActual "/" AnioActual 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 "Hoja" SPACE Pagina
         DISPLAY SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE
                 SPACE SPACE SPACE SPACE SPACE SPACE
                 "Listado de facturacion de recursos"
         DISPLAY SPACE
         .
         
       ListarTituloB.
         MOVE FUNCTION CURRENT-DATE() TO FechaActual
         ADD 1 TO Pagina

         DISPLAY "Fecha "
                 DiaActual "/" MesActual "/" AnioActual 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE 
                 "Hoja" SPACE Pagina
         DISPLAY SPACE SPACE SPACE SPACE SPACE SPACE 
                 SPACE SPACE SPACE SPACE SPACE SPACE
                 SPACE SPACE SPACE SPACE SPACE SPACE
                 "Listado de cantidad de horas no asignadas"
         DISPLAY SPACE
         .
       LeerSolicitudes.
         READ SOL-ARCH
	 AT END SET SOL-EOF TO TRUE
         END-READ
         .

       LeerAsignaciones.
         PERFORM LeerAsignacion1 
         PERFORM LeerAsignacion2 
         PERFORM LeerAsignacion3
         PERFORM AvanzarAsignaciones
         .

       LeerAsignacion1.
         READ ASI1-ARCH
           AT END SET ASI1-EOF TO TRUE
         END-READ
         .

       LeerAsignacion2.
         READ ASI2-ARCH
           AT END SET ASI2-EOF TO TRUE
         END-READ
         .

       LeerAsignacion3.
         READ ASI3-ARCH
           AT END SET ASI3-EOF TO TRUE
         END-READ
         .

       AvanzarAsignaciones.
         PERFORM UNTIL ASI1-EOF OR ASI1-CLAVE >= SOL-CLAVE
             PERFORM GrabarErrorAsignacion1
             PERFORM LeerAsignacion1
         END-PERFORM

         PERFORM UNTIL ASI3-EOF OR ASI3-CLAVE >= SOL-CLAVE
             PERFORM GrabarErrorAsignacion3
             PERFORM LeerAsignacion3
         END-PERFORM

         PERFORM UNTIL ASI2-EOF OR ASI2-CLAVE >= SOL-CLAVE
             PERFORM GrabarErrorAsignacion2
             PERFORM LeerAsignacion2
         END-PERFORM
         .

       GrabarErrorAsignacion1.
         MOVE ASI1-REG TO ERR-REG
         PERFORM GrabarErrorAsignacion
         .
         
       GrabarErrorAsignacion2.
         MOVE ASI2-REG TO ERR-REG
         PERFORM GrabarErrorAsignacion
         .

       GrabarErrorAsignacion3.
         MOVE ASI3-REG TO ERR-REG
         PERFORM GrabarErrorAsignacion
         .

       GrabarErrorAsignacion.
         WRITE ERR-REG
         .

       ListarTotalGeneral.
         DISPLAY "Total general                "
                 "          Horas: " TotalHorasGeneral
                 "    Asignacion: " TotalValorGeneral
         .

       DescartarAsignaciones.
         PERFORM UNTIL ASI1-EOF
           PERFORM GrabarErrorAsignacion1
           PERFORM LeerAsignacion1
         END-PERFORM

         PERFORM UNTIL ASI3-EOF
           PERFORM GrabarErrorAsignacion3
           PERFORM LeerAsignacion3
         END-PERFORM

         PERFORM UNTIL ASI2-EOF
           PERFORM GrabarErrorAsignacion2
           PERFORM LeerAsignacion2
         END-PERFORM
         .

         .

       DisplayLineaSimple.
         DISPLAY "----------------------------------------------------"
                 "-------------------------"
         .

       ListarCliente.
         PERFORM BuscarCategoriaCliente
         
         DISPLAY "Cod. Cliente: " SOL-COD-CLI-ANT SPACE
                 SPACE SPACE SPACE SPACE SPACE SPACE
                 "Cod. Categoria: " CLI-CATEGORIA
         .
         
       ListarTotalCliente.
         DISPLAY "Total para el cliente: " SOL-COD-CLI-ANT
                 "          Horas: " TotalHorasCliente
                 "    Asignacion: " TotalValorCliente
                 
         DISPLAY SPACE
         PERFORM DisplayLineaSimple
         DISPLAY SPACE
         
         .

       ListarFecha.
         DISPLAY SPACE
         DISPLAY " Fecha: " SOL-DIA-ANT "/" SOL-MES-ANT
                 "/" SOL-ANIO-ANT
         DISPLAY SPACE
         .


       ListarTotalFecha.
         DISPLAY " ===================================================="
                 "========================"
         DISPLAY SPACE
         DISPLAY " Total para la fecha: "
                 SOL-DIA-ANT "/" SOL-MES-ANT "/" SOL-ANIO-ANT
                 "        Horas: " TotalHorasFecha
                 "   Asignacion: " TotalValorFecha
         DISPLAY SPACE
         .

       ListarTitulos.
         DISPLAY " ===================================================="
                 "========================"
         DISPLAY " |  Perfil   | Seniority  |   Horas   |   Valor     |"
                 "    Valor asignacion   |"
         DISPLAY " ==================================================="
                 "========================"
         .

       ListarTitulosB.
         DISPLAY " ===================================================="
                 "====================================================="
                 "========================"
         DISPLAY " |  Perfil/Seniority  |" TabPerfiles(1) "|"
	 TabPerfiles(2) "|" TabPerfiles(3) "|" TabPerfiles(4) "|"
	 TabPerfiles(5) "|" TabPerfiles(6) "|" TabPerfiles(7) "|"
	 TabPerfiles(8) "|" TabPerfiles(9) "|" TabPerfiles(10) "|"
	 TabPerfiles(11) "|" TabPerfiles(12) "|" TabPerfiles(13) "|"
	 TabPerfiles(14) "|" TabPerfiles(15) "|" TabPerfiles(16) "|"
	 TabPerfiles(17) "|" TabPerfiles(18) "|" TabPerfiles(19) "|"
	 TabPerfiles(20) "|" TabPerfiles(21) "  |"
         DISPLAY " ===================================================="
                 "====================================================="
                 "========================"
	 .

       ListarPerfilSenior.
         PERFORM BuscarValorHora
         
         MULTIPLY SOL-CANT-HORAS-ANT BY ValorHora GIVING ValorAsignacion
       
         DISPLAY " |   " SOL-PERFIL-ANT "   "
                 " |    " SOL-SENIORITY-ANT "    "
                 " |    " SOL-CANT-HORAS-ANT "   "
                 " |    " ValorHora "  "
                 " |          " ValorAsignacion "    |"
         .


	GrabarSeniority.
	   MOVE "NO" TO Existe

	   PERFORM VARYING I FROM 1 BY 1
                   UNTIL I > 6 OR Existe = "SI"
	     IF (TabSenioritys(I) = SOL-SENIORITY)
	       MOVE "SI" TO Existe
	     END-IF
           END-PERFORM
	   
	   IF (Existe = "NO")
	   	MOVE 1 TO I
	   	MOVE "NO" TO Encontro
           	PERFORM VARYING I FROM 1 BY 1
                   UNTIL I > 6 OR Encontro = "SI"
             	IF TabSenioritys(I) = ""
               		MOVE SOL-SENIORITY TO TabSenioritys(I)

               		MOVE "SI" TO Encontro

             	END-IF
           	END-PERFORM
	   END-IF	
	.

	GrabarPerfil.

	   MOVE "NO" TO Existe
	   PERFORM VARYING I FROM 1 BY 1
                   UNTIL I > 20 OR Existe = "SI"
	     IF (TabPerfiles(I) = SOL-PERFIL)
	       MOVE "SI" TO Existe
	     END-IF
           END-PERFORM
	   
	   IF (Existe = "NO")
		   MOVE 1 TO I
		   MOVE "NO" TO Encontro
		   PERFORM VARYING I FROM 1 BY 1
		           UNTIL I > 20 OR Encontro = "SI"
		     IF TabPerfiles(I) = ""
		       MOVE SOL-PERFIL TO TabPerfiles(I)
		       MOVE "SI" TO Encontro

		     END-IF
		   END-PERFORM
	   END-IF
	   .	


       ProcesarAsignaciones1.
         PERFORM UNTIL ASI1-EOF OR ASI1-CLAVE <> SOL-CLAVE
           MOVE 'SI' TO HayAsignaciones
           
           ADD ASI1-CANT-HORAS TO HorasAsignacion
         

           IF HorasAsignacion > SOL-CANT-HORAS
             PERFORM GrabarErrorAsignacion1
           END-IF
           

           PERFORM LeerAsignacion1
         END-PERFORM
         .

       ProcesarAsignaciones2.
         PERFORM UNTIL ASI2-EOF OR ASI2-CLAVE <> SOL-CLAVE
           MOVE 'SI' TO HayAsignaciones
           
           ADD ASI2-CANT-HORAS TO HorasAsignacion
     

           IF HorasAsignacion > SOL-CANT-HORAS
             PERFORM GrabarErrorAsignacion2
           END-IF
           
           PERFORM LeerAsignacion2
         END-PERFORM
         .

       ProcesarAsignaciones3.
         PERFORM UNTIL ASI3-EOF OR ASI3-CLAVE <> SOL-CLAVE
           MOVE 'SI' TO HayAsignaciones
           
           ADD ASI3-CANT-HORAS TO HorasAsignacion
         
	
           IF HorasAsignacion > SOL-CANT-HORAS
             PERFORM GrabarErrorAsignacion3
           END-IF
           
           PERFORM LeerAsignacion3
         END-PERFORM
         .

       GrabarErrorSolicitud.
         MOVE SOL-COD-CLI-ANT    TO SASI-COD-CLI
         MOVE SOL-FECHA-ANT      TO SASI-FECHA
         MOVE SOL-PERFIL-ANT     TO SASI-PERFIL
         MOVE SOL-SENIORITY-ANT  TO SASI-SENIORITY
         MOVE SOL-CANT-HORAS-ANT TO SASI-CANT-HORAS
         WRITE SASI-REG

         PERFORM BuscarPosPerfil
	 PERFORM BuscarPosSeniority
	 PERFORM AcumTabSASI
         .
         
       BuscarCategoriaCliente.
         OPEN INPUT CLI-ARCH

         READ CLI-ARCH
           AT END SET CLI-EOF TO TRUE
         END-READ

         PERFORM UNTIL CLI-EOF OR CLI-COD-CLI = SOL-COD-CLI-ANT
           READ CLI-ARCH
             AT END SET CLI-EOF TO TRUE
           END-READ
         END-PERFORM
         
         IF CLI-EOF
           MOVE "--" TO CLI-CATEGORIA
         END-IF
         
         CLOSE CLI-ARCH
         .

       CargarTablaValores.
         MOVE 1 TO I
         
         OPEN INPUT VAL-ARCH

         READ VAL-ARCH
           AT END SET VAL-EOF TO TRUE
         END-READ
         
         PERFORM UNTIL VAL-EOF
           MOVE VAL-REG TO ItemValores(I)
      *    DISPLAY "||" TVL-PERFIL(I) "||" TVL-SENIORITY(I) "||"
      *    DISPLAY "||" TVL-VALOR(I, 1) "||" TVL-VALOR(I, 2) "||"

           ADD 1 TO I

           READ VAL-ARCH
             AT END SET VAL-EOF TO TRUE
           END-READ
         END-PERFORM

         CLOSE VAL-ARCH
         .

       BuscarValorHora.
         MOVE 0 TO ValorHora
         
         IF CLI-CATEGORIA <> '--'
           MOVE 1 TO I

           PERFORM VARYING I FROM 1 BY 1
                   UNTIL I > 100 OR ItemValores(I) = SPACES
             IF TVL-PERFIL(I) = SOL-PERFIL-ANT 
                AND TVL-SENIORITY(I) = SOL-SENIORITY-ANT

               MOVE TVL-VALOR(I, CLI-CATEGORIA) TO ValorHora
               MOVE HIGH-VALUES TO I 

             END-IF
           END-PERFORM
         END-IF
         .

       BuscarPosPerfil.

           MOVE "NO" TO Encontro
	   MOVE 1 TO I

           PERFORM VARYING I FROM 1 BY 1
                   UNTIL I > 20 OR Encontro = "SI"
             IF TabPerfiles(I) = SASI-PERFIL

               MOVE I TO posPerfil
               MOVE "SI" TO Encontro

             END-IF
           END-PERFORM
       	   .

       BuscarPosSeniority.
           MOVE "NO" TO Encontro
	   MOVE 1 TO I

           PERFORM VARYING I FROM 1 BY 1
                   UNTIL I > 6 OR Encontro = "SI"
             IF TabSenioritys(I) = SASI-SENIORITY

               MOVE I TO posSenior
               MOVE "SI" TO Encontro
	 
             END-IF
           END-PERFORM
           .
       
	AcumTabSASI.
	  ADD SASI-CANT-HORAS TO PERFIL(posSenior, posPerfil)
	  ADD SASI-CANT-HORAS TO PERFIL(7,posPerfil)
	  ADD SASI-CANT-HORAS TO PERFIL(posSenior,21)

          .

        ListarSolicitudesSinAsignacion.
          
	   PERFORM VARYING I FROM 1 BY 1
                   UNTIL I > 7

			DISPLAY "       " TabSenioritys(I) 
			"              "
			 PERFIL(I,1)"  "PERFIL(I,2)"  "PERFIL(I,3)"  "
			 PERFIL(I,4)"  "
			 PERFIL(I,5) "  " PERFIL(I,6) "  "
			 PERFIL(I,7) "  " PERFIL(I,8) "  "
			 PERFIL(I,9) "  " PERFIL(I,10) "  "
			 PERFIL(I,11) "  "  PERFIL(I,12) "  "
			 PERFIL(I,13) "  " PERFIL(I,14) "  "
			 PERFIL(I,15) "  " PERFIL(I,16) "  "
			 PERFIL(I,17) "  " PERFIL(I,18) "  "
			 PERFIL(I,19) "  " PERFIL(I,20) "  "

			 PERFIL(I,21)
	   END-PERFORM
           .

